package com.kingyun.gpsinspection.purificationservice.services.jsm.outerservice.impl;

import com.kingyun.gpsinspection.purificationservice.facade.model.jsm.*;
import com.kingyun.gpsinspection.purificationservice.facade.service.jsm.OutPermissionService;
import com.kingyun.gpsinspection.purificationservice.facade.service.jsm.permission.JsmAccountRoleService;
import com.kingyun.gpsinspection.purificationservice.facade.service.jsm.permission.JsmMenuService;
import com.kingyun.gpsinspection.purificationservice.facade.service.jsm.permission.JsmPermissionService;
import com.kingyun.gpsinspection.purificationservice.facade.service.jsm.permission.JsmSystemPlatformService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by huangxueqian on 2017/2/7/007.
 */

public class OutPermissionServiceImpl implements OutPermissionService {

    @Autowired
    private JsmPermissionService permissionService ;
    @Autowired
    private JsmSystemPlatformService systemPlatformService ;
    @Autowired
    private JsmMenuService menuService;
    @Autowired
    private JsmAccountRoleService accountRoleService;


    /**
     * @param systemCode 系统编码，
     * @param employeeVo  当前用户信息
     */
    @Override
    public List<Menu> getFirstNavPermission(String systemCode, EmployeeVo employeeVo,String pfToken) throws Exception {
        return permissionService.getFirstNavPermission(systemCode,employeeVo,pfToken);
    }

    /**
     *
     * @param systemCode 当前用户信息
     * @param employeeVo
     * @param menuId  根据一级菜单ID， 获取对应菜单权限
     */
    @Override
    public List<Menu> getLeftMenuNavPermission(String systemCode, EmployeeVo employeeVo, String menuId,String pfToken) throws Exception {
        return permissionService.getLeftMenuNavPermission(systemCode,employeeVo,menuId, pfToken);
    }

    /**
     * 获取平台详情 ；
     */
    @Override
    public List<SystemPlatform> selectSystemPlatform(String pfToken) throws Exception {
        return systemPlatformService.selectSystemPlatform(pfToken,"");
    }

    /**
     * @param url 根据url查询到一级菜单
     */
    @Override
    public Menu getRecordFirst(String url,String employeeId) throws Exception {
        return menuService.getFirstByUrl(url,employeeId);
    }

    public List<Menu> getAllMenuPermission(String pToken,String systemCode, EmployeeVo employeeVo) throws Exception{

       return permissionService.getAllMenuPermission(pToken,systemCode,employeeVo);
    }

    /**
     * 获取所有菜单
     * @param pToken
     * @param employeeVo
     * @return
     * @throws Exception
     */
    @Override
    public List<Menu> getAllMenu(String pToken, EmployeeVo employeeVo) throws Exception {
        boolean isAdmin = false ;
        List<AccountRole> accountRoles = accountRoleService.getRolesByAccount(employeeVo);
        /* 根据role获取菜单 */
        /* 判读是否是系统管理员，如果是系统管理员则查询该系统的一级菜单 */
        isAdmin = permissionService.isAdmin(accountRoles);
        return permissionService.getAllMenu(pToken,employeeVo,isAdmin);
    }


}
